// genertor:应用

// 场景1：发号器
function* makeID() {
    let i = 0;
    while (true) {
        yield i++
    }
}

const makeID_ge = makeID();
console.log(makeID_ge); //Object [Generator] {}
console.log(makeID_ge.next().value); //0
console.log(makeID_ge.next().value); //1
console.log(makeID_ge.next().value); //2

// 场景2：使用generator 函数实现iterator方法

const todos = {
    life: ['吃饭', '睡觉', '打游戏'],
    learn: ['数学', '英语', '中文'],
    work: ['donging...'],
    [Symbol.iterator]: function*() {
        const arr = [...this.life, ...this.learn, ...this.work];
        for (let i of arr) {
            yield i
        }
    }
}


for (let i of todos) {
    console.log(i);
}